﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using PumeCentralService;

namespace PumpeCentralServer
{
    class ServerMain
    {
        static void Main(string[] args)
        {
            bool ShouldTerminate = false;

            using (ServiceHost host = new ServiceHost(typeof(PumpCentralService),new Uri(PumpCentralServiceKonstants.URI)))
            {
                try
                {
                    host.AddServiceEndpoint(typeof(IPumpCentalService),new NetTcpBinding(),PumpCentralServiceKonstants.URI);

                    host.Open();

                    Console.WriteLine("PumpeCentralSerive er Online.");
                    Console.WriteLine("Indtast termineringskoden for at afbryde");
                    
                    while (!ShouldTerminate)
                    {
                        string command = Console.ReadLine();

                        if (command.ToLower() == "terminate")
                        {
                            ShouldTerminate = true;
                        }
                    }

                }
                catch (CommunicationException)
                {
                    host.Abort();
                }
            }

            Console.WriteLine("PumpeCentralService lukket");
            Console.ReadKey();

        }
    }
}
